home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / primcuts.zip / Extended Attributes / WriteEA.cpp < prev   
Text File  |  1997-01-11  |  4KB  |  146 lines

  1. #define INCL_DOSFILEMGR
  2.  
  3. #include <os2.h>
  4.  
  5. #include <iostream.h>
  6. #include <string.h>
  7.  
  8.  
  9. void SetFEA2(PFEA2 pFEA2, PCSZ pszName, USHORT usType, USHORT ulValSize, PVOID pValue, BYTE fEA = 0);
  10. void AddFEA2(PFEA2 *ppFEA2, PCSZ pszName, USHORT usType, USHORT ulValSize, PVOID pValue, BYTE fEA = 0);
  11. USHORT MakeFEA2String(PVOID pszOutBuf, PSZ pszInString);
  12. USHORT GetFEA2Size(PFEA2LIST pFEA2List);
  13.  
  14.  
  15. int main(int argc, char *argv[])
  16. {
  17.    APIRET   rc = 0;
  18.    EAOP2    eaop2;
  19.    char     pchInBuf[255];
  20.    PVOID    pTmpBuf;
  21.  
  22.    eaop2.fpGEA2List = 0;
  23.    eaop2.fpFEA2List = PFEA2LIST(new char[65535]);
  24.  
  25.    PFEA2 pFEA2 = &eaop2.fpFEA2List->list[0];
  26.  
  27.    pTmpBuf = new char[255];
  28.  
  29.  
  30.    cout << "Artist: ";
  31.    cin >> pchInBuf;
  32.  
  33.    USHORT   usLen;
  34.    usLen = MakeFEA2String(pTmpBuf, pchInBuf);
  35.    SetFEA2(pFEA2, "RT.ARTIST", EAT_ASCII, usLen, pTmpBuf, 0);
  36.  
  37.    cout << "Title: ";
  38.    cin >> pchInBuf;
  39.  
  40.    usLen = MakeFEA2String(pTmpBuf, pchInBuf);
  41.    AddFEA2(&pFEA2, "RT.TITLE", EAT_ASCII, usLen, pTmpBuf, 0);
  42.  
  43.    cout << "Record: ";
  44.    cin >> pchInBuf;
  45.  
  46.    usLen = MakeFEA2String(pTmpBuf, pchInBuf);
  47.    AddFEA2(&pFEA2, "RT.RECORD", EAT_ASCII, usLen, pTmpBuf, 0);
  48.  
  49.  
  50.    eaop2.fpFEA2List->cbList = GetFEA2Size(&eaop2.fpFEA2List[0]);
  51.  
  52.    rc = DosSetPathInfo(argv[1], FIL_QUERYEASIZE, &eaop2, sizeof(eaop2), 0);
  53.    if(rc != 0)
  54.    {
  55.       cout << "Error!" << endl;
  56.    }
  57. }
  58.  
  59.  
  60. void SetFEA2(PFEA2 pFEA2, PCSZ pszName, USHORT usType, USHORT usValSize, PVOID pValue, BYTE fEA)
  61. {
  62.    /* Set the required-flag */
  63.    pFEA2->fEA = fEA;
  64.  
  65.    /* Set the length of the EA-name and EA-value to the FEA structure*/
  66.    pFEA2->cbName = strlen(pszName);
  67.    pFEA2->cbValue = usValSize+sizeof(USHORT);  /* the extra USHORT for the type identifier */
  68.  
  69.    /* Copy the EA-name to the FEA-buffer */
  70.    strcpy(pFEA2->szName, pszName);
  71.  
  72.    /* Set a pointer for the EA-value after the EA-name */
  73.    char *pData = pFEA2->szName+pFEA2->cbName+1;
  74.  
  75.    /* Store the value-type */
  76.    *(PUSHORT)pData = EAT_ASCII;
  77.  
  78.    /* After the type, we store the actual EA-value */
  79.    memcpy(pData+sizeof(USHORT), pValue, usValSize);
  80.  
  81.    /* Make sure that this is the last entry */
  82.    pFEA2->oNextEntryOffset = 0;
  83. }
  84.  
  85.  
  86. void AddFEA2(PFEA2 *ppFEA2, PCSZ pszName, USHORT usType, USHORT usValSize, PVOID pValue, BYTE fEA)
  87. {
  88.    PFEA2 pFEA2 = *ppFEA2;
  89.  
  90.    pFEA2->oNextEntryOffset = sizeof(FEA2) + pFEA2->cbName + pFEA2->cbValue + 1;
  91.  
  92.    if(pFEA2->oNextEntryOffset)
  93.       pFEA2->oNextEntryOffset+= 4 - (pFEA2->oNextEntryOffset % 4);
  94.  
  95.    pFEA2 = (FEA2*)((char*)pFEA2 + pFEA2->oNextEntryOffset);
  96.  
  97.    SetFEA2(pFEA2, pszName, usType, usValSize, pValue, fEA);
  98.  
  99.    *ppFEA2 = pFEA2;
  100. }
  101.  
  102.  
  103. USHORT MakeFEA2String(PVOID pszOutBuf, PSZ pszInString)
  104. {
  105.    USHORT   usLen = 0;
  106.  
  107.    usLen = strlen(pszInString);
  108.  
  109.    *(PUSHORT)pszOutBuf = usLen;
  110.  
  111.    strncpy((char*)pszOutBuf+2, pszInString, usLen);
  112.  
  113.    return usLen+sizeof(USHORT);
  114. }
  115.  
  116.  
  117. USHORT GetFEA2Size(PFEA2LIST pFEA2List)
  118. {
  119.    USHORT   usSize = 0;
  120.    PFEA2    pFEA2 = &pFEA2List->list[0];
  121.  
  122.    usSize += sizeof(pFEA2List->cbList);
  123.  
  124.    while(pFEA2->oNextEntryOffset != 0)
  125.    {
  126.       usSize += sizeof(pFEA2[0].oNextEntryOffset);
  127.       usSize += sizeof(pFEA2[0].fEA);
  128.       usSize += sizeof(pFEA2[0].cbName);
  129.       usSize += sizeof(pFEA2[0].cbValue);
  130.  
  131.       usSize += pFEA2[0].cbName;
  132.       usSize += pFEA2[0].cbValue;
  133.  
  134.       pFEA2 = pFEA2 + pFEA2->oNextEntryOffset;
  135.    }
  136.    usSize += sizeof(pFEA2[0].oNextEntryOffset);
  137.    usSize += sizeof(pFEA2[0].fEA);
  138.    usSize += sizeof(pFEA2[0].cbName);
  139.    usSize += sizeof(pFEA2[0].cbValue);
  140.  
  141.    usSize += pFEA2[0].cbName;
  142.    usSize += pFEA2[0].cbValue;
  143.  
  144.    return usSize;
  145. }
  146.